#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std; 

int window(int work);
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct people{
	int id;
	int arrivetimem;
	int arrivetimeh;
	int work;
	struct people *next;
};
int main(int argc, char** argv) {
	int alltime=0;
	int customer=0;
	int a,b;
	struct people *first=NULL;
	struct people *second=NULL,*c2;
	struct people *third=NULL,*c3;
	struct people *fourth=NULL,*c4;
	struct people *c,*d; 
	while(1)
	{
	printf("1，系统自动初始化并开始模拟\n");
	printf("2，手动设置数据实现模拟\n请输入：\n");
	scanf("%d",&a);
	if(a==1)
	{
		break;
	}
	else if(a==2)
	{
		printf("1,qukuan"); 
		printf("请依次输入第1号顾客的到达时间和所需办理的业务（例：8 00 1  （8点到办理取款））");
		first=(struct people*)malloc(sizeof(struct people));
		first->id  =1;
		scanf("%d%d%d",&first->arrivetimeh ,&first->arrivetimem ,&first->work );
		d=c;
		for(int e=2;e<10000;e++)
		{
			printf("1，继续取号\n2，取号完成并开始模拟\n"); 
		    scanf("%d",&b);
		    if(b==1)
		   {
			printf("请输入第%d号顾客到达时间和业务",e);
			c=(struct people*)malloc(sizeof(struct people));
			c->id =e;
			scanf("%d%d%d",&c->arrivetimeh ,&c->arrivetimem ,&c->work );
			c->next =NULL; 
			d->next =c;
			d=c;
	     	}
	    	else if(b==2)
		   {
			break;
		   }
		   else
		   {
			printf("输入错误请重新输入：");
			e--;
	     	}	
		}	
		break;
	}
	else
	{
		printf("输入错误请重新输入：");
	}
	
	 } 
	//开始模拟
	c=first;
	for(int i=8;i<12;i++)
	{
		for(int j=0;j<60;j++)
		{
			if(c->arrivetimeh ==i)
			{
				if(c->arrivetimem ==j)
				{
				    j=j+window(c->work );
				    
				    if(j>60)
				    {
				    	i++;
				    	j=j-60;
				    	if((i>=12)&&(j>0))
				    	{
				    		break;
						}
					}
					printf("第%d号顾客再第1号窗口办理完业务",c->id );
					customer++;
					alltime=alltime+((i*60+j)-(c->arrivetimeh *60+c->arrivetimem ));
					c=c->next ;
					while(1)
					{
					   if((i*60+j)>(c->arrivetimeh *60+c->arrivetimem ))
					   {
					   	if(second==NULL)
					   	{
					   		second=c;
					   		c=c->next ;
					   		c2=c;
						   }
						   else
						   {
						   	c2->next =c;
						   	c2=c2->next ;
						   }
					   }
					   else
					   {
					   	
					   }
					   
					}
					
					
				}
			}
			else if(i>12)
			{
				break;
			}
		}
	 } 
	
	return 0;
}

int window(int work)
{
	return work*10;
}